<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	findCompNm		= Request("findCompNm")
	findPrdNm		= Request("findPrdNm")
	findLotNo	= Request("findLotNo")
	findLotYear	= Request("findLotYear")
	findType		= Request("findType")
	goodsCnt		= Request("findGoods")

	If goodsCnt = "" Then goodsCnt = 0 End If 

	
	SQLTitle = "-- ■■■■ 작업지시 관리 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If findCompNm <> "" Then 
		addSql = " B.company LIKE '%" & findCompNm & "%' "
	End If 
	If findPrdNm <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " P.prdNm LIKE '%" & findPrdNm & "%' "
	End If 
	If findLotNo <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.lotYear+A.lotNo LIKE '%" & findLotNo & "%' "
	End If 
	If findLotYear <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.lotYear='" & findLotYear & "' "
	End If 
	If findType <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.type = '" & findType & "' "
	End If 
	If goodsCnt > 0 Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.goodsQty >= " & goodsCnt
	End If 
	If addSql <> "" Then 
		addSql = " WHERE " & addSql 
	End If 

	SQL = "SELECT A.lotYear+A.lotNo fullLotNo, A.lotSubNo, B.company, P.prdNm, A.qty, A.deliveryDt, C.procTypeNm, A.sourceLotNo, A.sourceSize, ISNULL(A.ingQty,0) ingQty, A.flag, A.type, ISNULL(A.amount,0) amount, ISNULL(D.processNm,'준비') curProcess, ISNULL(A.goodsQty,0) goodsQty, A.restQty, CAST(ISNULL(A.badRate,0) as VARCHAR(10)) badRate, E.etc, A.type, A.testedQty " & _
		  " FROM tblOrder A LEFT JOIN tblCompany B ON A.compCd=B.compCd " & _
		  "		LEFT JOIN tblProcSet C ON A.procTypeCd=C.procTypeCd " & _
		  "		LEFT JOIN tblUnitProcess D ON A.curProcessCd=D.processCd " & _		  
		  "		LEFT JOIN (SELECT * FROM tblOrderResult WHERE type='10' AND rank='100')  E ON E.lotYear+E.lotNo=A.lotYear+A.lotNo AND E.lotSubNo=A.lotSubNo" & _		  
		  "		LEFT JOIN tblProduct P ON A.prdCd=P.prdCd " & addSql & _
		  " ORDER BY A.lotYear DESC, A.lotNo DESC, A.lotSubNo DESC" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 
'Response.write SQL
	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<JobOrder>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof	
			badRate = rs("badRate")
			If badRate = "100.000" Then 
				badRate = "100"
			ElseIf badRate = "0.000" Then 
				badRate = "0"
			End If 
			badRate = Round(badRate,1)
			If rs("type") = "D" Then badRate = "&nbsp;" End If 
			deliveryDt = Replace(rs("deliveryDt"),"-",".")
			Response.write "	<OrderList>" & vbcrlf
				Call mkXMLNode("fullLotNo", rs("fullLotNo"), 2)
				Call mkXMLNode("lotSubNo", rs("lotSubNo"), 2)
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("curProcess", rs("curProcess"), 2)
				Call mkXMLNode("prdNm", rs("prdNm"), 2)
				Call mkXMLNode("qty", FormatNumber(rs("qty"),0) & "/" & FormatNumber(rs("restQty"),0), 2)
				Call mkXMLNode("deliveryDt", deliveryDt, 2)
				Call mkXMLNode("procTypeNm", rs("procTypeNm"), 2)
				'Call mkXMLNode("sourceLotNo", rs("sourceLotNo"), 2)
				Call mkXMLNode("etc", left(rs("etc"),2) & "/" & rs("testedQty"), 2)
				Call mkXMLNode("ingQty", FormatNumber(rs("ingQty"),0), 2)
				Call mkXMLNode("type", rs("type"), 2)
				Call mkXMLNode("amount", FormatNumber(rs("amount"),0), 2)
				Call mkXMLNode("goodsQty", FormatNumber(rs("goodsQty"),0), 2)
				Call mkXMLNode("badRate", badRate, 2)
				Call mkXMLNode("flag", Rs("flag"), 2)
			Response.write "	</OrderList>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</JobOrder>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>